package com.cc.pms.service.impl;

import com.cc.common.core.domain.R;
import com.cc.common.utils.DateUtils;
import com.cc.common.utils.SecurityUtils;
import com.cc.pms.domain.TeamChat;
import com.cc.pms.domain.vo.TeamChatVo;
import com.cc.pms.mapper.TeamChatMapper;
import com.cc.pms.service.ITeamChatService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 存储队伍内部的聊天记录 服务实现类
 * </p>
 *
 * @author corleone
 * @since 2025-04-19
 */
@Service
public class TeamChatServiceImpl extends ServiceImpl<TeamChatMapper, TeamChat> implements ITeamChatService {

    @Override
    public List<TeamChatVo> queryTeamChatRecord(Long teamId) {
        return baseMapper.queryTeamChatRecord(teamId);
    }

    @Override
    public R<Long> sendTeamChatMessage(TeamChat teamChat) {
        if (teamChat == null || teamChat.getContent() == null || teamChat.getContent().trim().isEmpty()){
            return R.fail(-1 ,"发送消息失败,消息不能为空");
        }
        teamChat.setSendTime(DateUtils.getTime());
        teamChat.setUserId(SecurityUtils.getUserId());
        return save(teamChat) ? R.ok(teamChat.getId() , "发送成功") : R.fail(-1 , "发送失败");
    }
}
